package com.tanhua.server.controller;

import com.tanhua.server.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.xml.crypto.Data;
import java.util.Map;

@RestController
@RequestMapping("/messages")
public class MessageController {
    @Autowired
    private MessageService messageService;
    /**
     * 消息-添加联系人（聊一下  添加好友）
     * POST /messages/contacts
     */
    @PostMapping("/contacts")
    public ResponseEntity addContact(@RequestBody Map map){
        long targetUserId = Long.parseLong(map.get("userId").toString());
        return messageService.addContacts(targetUserId);
    }
    /**
     * 消息-联系人列表
     * GET /messages/contacts
     */
    @GetMapping("/contacts")
    public  ResponseEntity findContactsList(@RequestParam(defaultValue = "1") int page,
                                            @RequestParam(defaultValue = "10")int pagesize,
                                            @RequestParam(required = false)String keyword){
        return messageService.findContactList(page,pagesize,keyword);
    }
/**
 * 消息-点赞列表（点赞commentType:1）
 * GET /messages/likes
 */
@GetMapping("/likes")
    public ResponseEntity findLikeList(@RequestParam(defaultValue = "1") int page,
                                       @RequestParam(defaultValue = "10") int pagesize){
    return messageService.findCommentList(1,page,pagesize);
}
/**
 * 消息-评论列表（评论commentType:2）
 * GET /messages/comments
 */
@GetMapping("/comments")
    public ResponseEntity findCommentsList (@RequestParam(defaultValue = "1") int page,
                                            @RequestParam(defaultValue = "10")int pagesize){
    return messageService.findCommentList(2,page,pagesize);
}
/**
 * 消息-喜欢列表（喜欢commentType:3）
 * GET /messages/loves
 */
@GetMapping("/loves")
    public  ResponseEntity findLoveList(@RequestParam(defaultValue = "1")int page,
                                        @RequestParam(defaultValue ="10")int pagesize){
    return messageService.findCommentList(3,page,pagesize);
}
}
